part of my_base_lib;

class DateFormat{

  static const String format1 = "yyyy/MM/dd HH:mm:ss:sss";
  static const String format2 = "yyyy-MM-dd";
  static String format(int timestamp,String format){
    DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp);
    String month = '${dateTime.month}';
    if(month.length<2){
      month="0$month";
    }
    String day = '${dateTime.day}';
    if(day.length<2){
      day="0$day";
    }
    String hour = '${dateTime.hour}';
    if(hour.length<2){
      hour="0$hour";
    }
    String minute = '${dateTime.minute}';
    if(minute.length<2){
      minute="0$minute";
    }
    String second = '${dateTime.second}';
    if(second.length<2){
      second="0$second";
    }
    String millisecond = '${dateTime.millisecond}';
    if(millisecond.length<3){
      millisecond="0$millisecond";
    }
    if(millisecond.length<3){
      millisecond="0$millisecond";
    }

    return format
        .replaceAll("yyyy", '${dateTime.year}')
        .replaceAll("MM", month)
        .replaceAll("dd", day)
        .replaceAll("HH", hour)
        .replaceAll("mm", minute)
        .replaceAll("sss", millisecond)
        .replaceAll("ss", second)

    ;
  }

}